1. /* scfcpowc.cpp by K.Tsuru */
  2. // function ID = 9106
  3. /*****************************************************************************
  4. SComplex class
  5. It returns z^a = exp(a*log(z)).
  6. Let z = x+i*y, a = c+i*d,
  7. a*log(z) = (c+i*d)*log(x+i*y)
  8. = (c+i*d)*{(1/2)*log(x^2+y^2)+i*arctan(y/x)}
  9. = {c*(1/2)*log(x^2+y^2)-d*arctan(y/x)}+i*{d*(1/2)*log(x^2+y^2)+c*arctan(y/x)}
  10. = (c*r-d*t)+i*(d*r+c*t)
  11. = p+i*q
  12. where r = (1/2)*log(x^2+y^2), t = arctan(y/x) ), p = c*r-d*t, q = d*r+c*t.
  13. Then
  14. z^a = exp(p+i*q) = exp(p)*{cos(q)+i*sin(q)}
  15. = polar(exp(p), q)
  16. Notice the relation : arctan(y/x) = atan2(y, x) = arg(z)
  17. *******************************************************************************/
  18. #ifndef SN_H
  19. #include "sn.h"
  20. #endif
  21. #define UsesSimpleVersionInCpowC 1
  22. SComplex Cpow(const SComplex& z, const SComplex& a){
  23. if( z.IsZero(9106) ) SNManager::SetError(SNManager::DOMAIN_ERR, "Cpow", 9106);// x == 0
  24. if(a.IsZero(9106)) return SComplex(1.0, 0.0); // a == 0
  25. #if UsesSimpleVersionInCpowC // 241(sec) faster a little
  26. // simple version
  27. SComplex y, result;
  28. y = Clog(z);
  29. y *= a;
  30. result = Cexp(y);
  31. return result;
  32. #else // 244(sec)
  33. SDouble r = z.Norm(); // = x^2+y^2
  34. r = Log(r)/2.0; // (1/2)*log(x^2+y^2)
  35. SDouble t = Arg(z), p, q;
  36. p = a.Real()*r - a.Imag()*t;
  37. p = Exp(p);
  38. q = a.Imag()*r + a.Real()*t;
  39. return Cpolar(p, q);
  40. #endif
  41. }

scfcpowc.cpp : last modifiled at 2015/09/09 15:08:14(1,370 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:09 (Fri Oct 06 15:27:09 2017).